-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pylint]
Implement use-implicit-booleaness-not-len
(PLC1802
)
#14309
base: main
Are you sure you want to change the base?
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLC1802 | 16 | 16 | 0 | 0 | 0 |
C1802
)C1802
)
C1802
)[pylint]
Implement use-implicit-booleaness-not-len (C1802
)
[pylint]
Implement use-implicit-booleaness-not-len (C1802
)[pylint]
Implement use-implicit-booleaness-not-len
(C1802
)
[pylint]
Implement use-implicit-booleaness-not-len
(C1802
)[pylint]
Implement use-implicit-booleaness-not-len
(PLC1802
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this contribution! Some minor nits/requests for a few more tests. I also didn't get a chance to review the implementation carefully, but I'll hold off for now in case the new tests inspire any changes.
crates/ruff_linter/resources/test/fixtures/pylint/len_as_condition.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test some more complicated examples involving rebindings/scope since you use those properties of the semantic model? Maybe something like:
def f(cond:bool):
x = [1,2,3]
if cond:
x = [4,5,6]
if len(x):
print(x)
and
def g(cond:bool):
x = [1,2,3]
if cond:
x = [4,5,6]
if len(x):
print(x)
del x
and
def h(cond:bool):
x = [1,2,3]
x = 123
if len(x):
print(x)
and
def outer():
x = [1,2,3]
def inner(x:int):
return x+1
if len(x):
print(x)
or any others you can think of to exercise the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this implementation does support only one name assignment in current scope.
It would be fair to check all prior assignments to this.
Summary
This PR implements
use-implicit-booleaness-not-len
/C1802
Test Plan
Checked against pylint tests:
Notes
len-as-condition
might be solution)References
PEP 8 on empty sequences and implicit booleaness